package com.sunnyebuy.merchant.util;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

/**
 * <p> Title: SpringUtil.java </p>
 * 
 * <p> Description: com.sunnyebuy.merchant.util </p>
 * 
 * <p> Copyright: Copyright (c) 2008-2011 All rights reserved.</p>
 *
 *<p> Created: 2011-12-29 下午3:13:59 </p>
 * 
 * @author Wenzhong Gu
 * 
 * @version 1.0
 */
public class SpringUtil implements ApplicationContextAware, DisposableBean{

	private static ApplicationContext applicationContext = null;
	
	/* (non-Javadoc)
	 * @see org.springframework.context.ApplicationContextAware#setApplicationContext(org.springframework.context.ApplicationContext)
	 */
	@Override
	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
		SpringUtil.applicationContext = applicationContext;		
	}

	/* (non-Javadoc)
	 * @see org.springframework.beans.factory.DisposableBean#destroy()
	 */
	@Override
	public void destroy() throws Exception {
		applicationContext = null;
	}

	/**
	 * 获取applicationContext
	 * 
	 * @return applicationContext
	 */
	public static ApplicationContext getApplicationContext() {
		return applicationContext;
	}

	
	public static Object getBean(String name) throws BeansException {
		return applicationContext.getBean(name);
	}
	
}